package com.zhang.codeGenerator.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author ZhangJunqi
 * @Date 2022/3/27 -12:36
 */
@MapperScan("com.zhang.codeGenerator.mapper")
@EnableTransactionManagement
@Configuration
public class MyBatisConfig {
    // 注册乐观锁插件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor ();
        interceptor.addInnerInterceptor (new OptimisticLockerInnerInterceptor ());
        //添加分页
        interceptor.addInnerInterceptor (new PaginationInnerInterceptor (DbType.MYSQL));
        return interceptor;
    }
}
